package mobi.hami.huapin.dao;

import mobi.hami.huapin.daobase.CrudMapper;
import mobi.hami.huapin.model.NoteSort;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;


import java.util.List;
import java.util.Map;

@Repository
public interface NoteSortMapper extends CrudMapper<NoteSort> {

    @SelectProvider(type = NoteSortProvider.class,method = "selectNoteSortsWitchParam")
    List<NoteSort> selectNoteSortsWitchParam(Map<String,Object> parms);


    /**
     * 更新纸条分类状态
     * @param id
     * @param status
     * @return
     */
    @Update("update note_sort set status = #{status} where id = #{id}")
    int updataNoteSortStatus(@Param("id") Integer id,@Param("status") Integer status);
    /**
     * 查询分类的最大排序号
     */
    @Select("select max(order_num) from note_sort")
    int selectMaxOrderNum();
    /**
     * 更新拍序号
     */
    @Update("update note_sort set order_num = #{order_num} where id = #{id}")
    int updataOrderNum(@Param("id") Integer id,@Param("order_num") Integer order_num);
    /**
     * 升序 获得拍序号第一个
     */
    @Select("select * from note_sort where order_num > #{order_num} order by order_num asc LIMIT 1")
    NoteSort getOrderNumASC(@Param("order_num") Integer order_num);
    /**
     * 降序 获得拍序号第一个
     */
    @Select("select * from note_sort where order_num < #{order_num} order by order_num desc LIMIT 1")
    NoteSort getOrderNumDESC(@Param("order_num") Integer order_num);
    /**
     * 更新版本号
     */
    @Update("update note_sort set version = #{version} where id = #{id}")
    int updateVersion(@Param("id") Integer id,@Param("version") Long version);


}